package com.dmz.workflow.util;

import com.thoughtworks.paranamer.ParameterNamesNotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class BeanUtilsExt {

    public static <S, T> List<T> copyObjectListProperties(List<S> src, Class<T> clazz) {
        if (ObjectUtils.isEmpty(src)) {
            throw new ParameterNamesNotFoundException("src object is null");
        }
        List<T> tar = new ArrayList<>();
        for (Object o : src) {
            T t = null;
            try {
                t = clazz.newInstance();
            } catch (Exception e) {
                log.info(e.getMessage());
            }
            if (ObjectUtils.isNotEmpty(t)) {
                BeanUtils.copyProperties(o, t);
                tar.add(t);
            }
        }
        return tar;
    }
}
